/** 窗口滚动距离 */
const scrollY = ref<number>(0);
/** 可视窗口Height */
const clientHeight = ref(0);
/** 是否显示顶部导航 */
const isShowNavigation = ref(true);

/** 导航隐藏、显示 */
if (process.client) {
  window.addEventListener("resize", Utils.throttle(500, updateClientHeight));
  window.addEventListener("scroll", Utils.throttle(500, scrollCaback));
  updateClientHeight();
}

/** 更新可视高度 */
function updateClientHeight() {
  clientHeight.value = document.documentElement.clientHeight;
}

/** top不超过50vh或者上滑-> 显示Head, 否则->隐藏 */
function scrollCaback() {
  const newY = window.scrollY;
  const up = newY - scrollY.value < 0;
  scrollY.value = newY;
  isShowNavigation.value = newY < 0.5 * clientHeight.value || up;
}

export { scrollY, clientHeight, isShowNavigation };
